import { defineStore } from 'pinia'
import { requestPoetry, requestSearchPoetry, requestDeletePoetryById, requestAddPoetry, requestUpadatePoetryById, requestPoetryByLid } from './manage-poetry.api'

export default defineStore('managePoetry', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取全部诗歌信息
        getPoetry(data: object) {
            return new Promise((resolve, reject) => {
                requestPoetry(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据诗歌名称/诗句/朝代/诗人查找诗歌信息
        getSearchPoetry(data: object) {
            return new Promise((resolve, reject) => {
                requestSearchPoetry(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid删除诗歌信息
        getDeletePoetryById(data: object) {
            return new Promise((resolve, reject) => {
                requestDeletePoetryById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 添加诗歌信息
        getAddPoetry(data: object) {
            return new Promise((resolve, reject) => {
                requestAddPoetry(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据id更改诗歌信息
        getUpadatePoetryById(data: object) {
            return new Promise((resolve, reject) => {
                requestUpadatePoetryById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据标签获取诗歌
        getPoetryByLid(data: Object = {}) {
            return new Promise((resolve, reject) => {
                requestPoetryByLid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
    }
})
